<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-合同录入页</title>
		<style>
		#organizesTree {
			margin-top: 10px;
			border: 1px solid #617775;
			background: #f0f6e4;
			min-width: 180px;
			max-height: 400px;
			overflow-y: scroll;
			overflow-x: auto;
		}
		</style>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js">
		</script>
        <script type="text/javascript" src="<%=path%>/js/My97DatePicker/WdatePicker.js">
        </script>
		<link rel="stylesheet" type="text/css" 
		    href="<%=path%>/js/My97DatePicker/skin/WdatePicker.css"/>
		    		<link type="text/css" rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css" />	
		<link type="text/css" href="<%=path%>/js/jquery-ui-1.8.21.custom/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.1.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.1.min.js"></script>
		<script type="text/javascript" src="<%=path%>/js/jquery-ui-1.8.21.custom/js/jquery-ui-1.8.21.custom.min.js">
		</script>
<script type="text/javascript">
function doSubmit(url) {
//	document.forms[0].action = url;
	//document.forms[0].submit();
	document.getElementById("formID").action = url;
	document.getElementById("formID").submit();
	//$('#frmID').html();
}

function cancle(url)
{
  if(confirm("您确认取消本次操作？"))
  {
     doSubmit(url);
  }
  else
  {
  
  }

}

//合同名称不能重复
function contractNameBlur(contractName)
{
		var item = $.trim($(contractName).val());
		var currentName = "${contractModify.contractName}";
	    if (null != item && item != '') {
	    if(item!=currentName)
		{
			var url = encodeURI(encodeURI('isExistContractName.action?contract.contractName=' + item));
			$.ajax( {
				url : url,
				type : "POST",
				cache : false,
				success : function(message) {
					if (message == "success") {
						alert("合同名称已存在，请重新输入！");
						$(contractName).focus();
					}
				}
			});
		}
	}
	
}
function addSubFrm() {
	var myReg = /^[^@\/\'\\\"#$%&\^\*<>]+$/;
    var contractNum = /^[\w-\s]+$/;
	//合同名称
	var tmpContractName = $.trim(document.getElementById("contractName").value);
	document.getElementById("contractName").value = tmpContractName;
	if (tmpContractName == '') {
		alert('合同名称不能为空！');
		return false;
	}
	if (!myReg.test(tmpContractName)) {
		alert("合同名称不能包含：“$、#、%、/、*、<、>、'、\"、\\、& ”等特殊字符，请重新输入！");
		document.getElementById('contractName').focus();
		return false;
	}
	if (getLen(tmpContractName) > 240) {
		alert("合同名称应不大于80个汉字(240个字符)！");
		return false;
	}
	//供应商名称
	var tmpContractBName = $.trim(document.getElementById("contractBName").value);
	document.getElementById("contractBName").value = tmpContractBName;
	if (tmpContractBName == '') {
		alert('供应商名称不能为空！');
		return false;
	}
	if (!myReg.test(tmpContractBName)) {
		alert("供应商名称不能包含：“$、#、%、/、*、<、>、'、\"、\\、& ”等特殊字符，请重新输入！");
		document.getElementById('contractBName').focus();
		return false;
	}
	if (getLen(tmpContractBName) > 240) {
		alert("供应商名称应不大于80个汉字(240个字符)！");
		return false;
	}
	//开始时间
	var tmpContractStartTime = $.trim(document.getElementById("contractStartTime").value);
	if (tmpContractStartTime == '') {
		alert('开始时间不能为空！');
		return false;
	}
	
	//结束时间
	var tmpContractEndTime = $.trim(document.getElementById("contractEndTime").value);
	if (tmpContractEndTime == '') {
		alert('截止时间不能为空！');
		return false;
	}
	if(tmpContractEndTime<tmpContractStartTime)
	{
	    alert('截止时间不能小于开始时间！');
		return false;
	}
	var tempContractOrganize = $.trim(document.getElementById("showOrganize").value);
	if(tempContractOrganize =='')
	{
	    alert('请选择用户所属部门科室！');
	    return false;
	}
	//签约人
    var tmpContractor = $.trim(document.getElementById("contractor").value);
	document.getElementById("contractor").value = tmpContractor;
	if (tmpContractor == '') {
		alert('签约人不能为空，请重新选择部门科室！');
		return false;
	}
	//合同描述
	var tmpContractDescription = trim(document.getElementById("contractDescription").value);
	if (getLen(tmpContractDescription)>900) {
		alert("合同描述应不大于300个汉字(900个字符)！");
		return false;
	}
	doSubmit('updataModifyContract.action');
}
function trim(str) {
	str = str.replace(/^\s*/, "");
	str = str.replace(/\s*$/, "");
	str = str.replace(/^[" "|"　"]*/, "");
	str = str.replace(/[" "|"　"]*$/, "");
	return str;
}
 
 //获取输入框中的字符长度
   function getLen(str){
		var len=0;
		if(null!=str&&str!=""){
			for(var i=0;i<str.length;i++){
				var intCode=str.charCodeAt(i);
				//如果ASCII码等于34(")38(&)39(')47(/)60(<)62(>)92(\)也算三个字符
				if (intCode>=0&&intCode<=127&&intCode!=34&&intCode!=39&&intCode!=47&&intCode!=60&&intCode!=62&&intCode!=92){
					len=len+1;
				}else{
					len=len+3;
				}
			}
		}
		return len;
	}
    //下载文件
 function downloadFile(fileName)
 {
	 var url = encodeURI(encodeURI("downLoadContractFileName.action?fileName=" +fileName));
	 window.location.href=url;
 }
</script>
	</head>

	<body>
		<!-- 顶栏start -->
		<jsp:include page="../common/top.jsp"></jsp:include>

		<!-- 顶部start -->
		<div id="main">
			<div class="body">
				<!-- 导航菜单 -->
				<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<div class="main_body">
				<table class="condition" style="width:100%; font-size:14px; font-weight:bold; color:#000000;" align="center">
					<tr>
						<td>
						    <s:if test="%{null == contractModify}">
							&nbsp;&nbsp;&nbsp;
							<input type="button" class="btn-title" value="返回" onclick="doSubmit('contractlist.action');" />
							</s:if>
						</td>
					</tr>
				</table>
				<form  id="formID" method="post"  enctype="multipart/form-data">
					<div id="add_div">
						<table class="table_add" style="width: 100%;">
						<s:if test="%{null == contractModify}">
							<tr>
								<th style="width: 150px; text-align: center;color: red" colspan="3">
									 该条记录不存在或已删除！									
								</th>
							</tr>
							</s:if>
							<s:else>
							<tr>
								<th style="width: 150px;">
									合同编号：
								</th>
								<td style="width: 225px;">
									<input type="text" class="text" readonly="readonly" name="contractUpdataModify.contractID" id="contractID" value="${contractModify.contractID}" style="width: 225px;" /><font color="red" > *</font>
								</td>
								<th style="width: 189px;">
									合同名称：
								</th>
								<td>
									<input type="text" class="text" name="contractUpdataModify.contractName" maxlength="240"  onblur="contractNameBlur(this);" id="contractName" value="${contractModify.contractName}" style="width: 225px;" /><font color="red" > *</font>
								</td>
							</tr>
							<tr>
								<th style="width: 150px;">
									供应商名称：
								</th>
								<td style="width: 225px;">
									<input type="text" class="text" name="contractUpdataModify.contractBName" maxlength="240" id="contractBName" value="${contractModify.contractBName}" style="width: 225px;" /><font color="red" > *</font>
								</td>
								<th style="width: 189px;">
									供应商类型：
								</th>
								<td>
									<s:select cssStyle="width: 227px;" name="contractUpdataModify.contractBType" id="contractBType"  value="contractModify.contractBType" list="dataListGYSLX" listKey="id" listValue="datavalue">
									</s:select><font color="red" > *</font>
								</td>
							</tr>
							<tr>
								<th style="width: 150px;">
									合同类型：
								</th>
								<td style="width: 225px;">
									<s:select cssStyle="width: 227px;" name="contractUpdataModify.contractType" id="contractType" value="contractModify.contractType" list="dataListHTLX" listKey="id" listValue="datavalue">
									</s:select><font color="red" > *</font>
								</td>
								<th style="width: 189px;">
									签约级别：
								</th>
								<td style="width: 225px;">
									<s:select cssStyle="width: 227px;" name="contractUpdataModify.contractLevel" id="contractLevel" value="contractModify.contractLevel" list="dataListQYJB" listKey="id" listValue="datavalue">
									</s:select><font color="red" > *</font>
								</td>
							</tr>
							<tr>
								<th style="width: 150px;">
									开始时间：
								</th>
								<td style="width: 225px;">
									<input type="text" class="text Wdate" name="contractUpdataModify.contractStartTime" 
									id="contractStartTime" 
									value="${fn:substring(contractModify.contractStartTime,0,10)}"
									onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" style="width: 225px;" /><font color="red" > *</font>
								</td>
								<th style="width: 189px;">
									截止时间：
								</th>
								<td>
									<input type="text" class="text Wdate" name="contractUpdataModify.contractEndTime" 
									id="contractEndTime" 
									value="${fn:substring(contractModify.contractEndTime,0,10)}"
									onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"  style="width: 225px;" /><font color="red" > *</font>
								</td>
							</tr>
							<tr>
								<th style="width: 150px;">
									部门科室：
								</th>
								<td style="width: 225px;">
								    <input type="hidden"  id="orgID" name="contractUpdataModify.contractDepartment" value="${contractModify.contractDepartment}"/>
									<input name="text2" type="text" class="text" id="showOrganize"
										style="width: 225px; text-valign:middle; line-height:23px;" onkeydown="if(event.keyCode==8)return false;"
										onclick="showMenu('showOrganize', 'organizeContent');" value="${contractDepartmentName}" readonly/>
									<font color="red" > *</font>
								</td>
								<th style="width: 189px;">
									归属地市：
								</th>
								<td  style="width: 225px;">
									<s:select cssStyle="width: 227px;" name="contractUpdataModify.contractCity" id="contractCity" value="contractModify.contractCity" list="dataListCITY" listKey="id" listValue="datavalue">
									</s:select><font color="red" > *</font>
								</td>
		
							</tr>
							<tr>
								<th style="width: 150px;">
									付款方式：
								</th>
								<td  style="width: 225px;">
									<s:select cssStyle="width: 227px;" name="contractUpdataModify.contractPayment" id="contractPayment" value="contractModify.contractPayment" list="dataListFKFS" listKey="id" listValue="datavalue">
									</s:select><font color="red" > *</font>
								</td>
								<th style="width: 189px;">
									签约人：
								</th>
								<td colspan="3" style="width: 225px;">
								    <s:select cssStyle="width: 227px;" name="contractUpdataModify.contractor" value="contractModify.contractor" id="contractor" list="dataListUSER" listKey="id" listValue="userName" >
									</s:select>
									<font color="red" > *</font>
								</td>
							</tr>
							<tr>
								<th style="width: 150px;">
									合同电子文件：
								</th>
								<td colspan="3" style="width: 225px;">
									<input type="file"  name="inputfile" id="inputfile" 
										style="width: 227px; height:21px; solid 1px #999999;" />&nbsp;&nbsp;${contractModify.contractFilename}
								<a href="javascript:downloadFile('${contractModify.contractFilename}');" title="下载"><img align="absmiddle" src=" <%=path%>/images/download.gif" alt="下载" /></a>
								</td>
							</tr>
							<tr>
								<th style="width: 150px;">
									合同描述：
								</th>
								<td colspan="3">
									<textarea name="contractUpdataModify.contractDescription" id="contractDescription" style="width: 647px; font-family: '微软雅黑'; font-size: 12px; font-weight: bold; color: #666666;">${contractModify.contractDescription}
									</textarea>
								</td>
							</tr>
						</s:else>
						</table>
					</div>
					<s:if test="%{null != contractModify}">
					<div style="margin: 8px 0 0 150px;">
						<input type="button" class="btn-title" value="保存"
							id="saveBtn" onclick="addSubFrm();" />
						<input type="button" class="btn-title" value="取消"
							onclick="cancle('contractlist.action');" />
					</div>
					</s:if>
				</form>
				</div>
			</div>
		</div>
		<!-- 顶部end -->
		<div id="organizeContent" class="menuContent"
			style="display: none; position: absolute;">
			<ul id="organizesTree" class="ztree" style="margin-top: 0;"></ul>
		</div>

		<!-- 底部start -->
		<div id="bottom">
			<div class="body">
				<label>
					版权所有&nbsp;&nbsp;&nbsp;&nbsp;2012东莞移动
				</label>
			</div>
		</div>
		<div id="tempDiv"></div>
		<!-- 底部end -->
		<script type="text/javascript">
	
	//获取后台数据显示组织架构
	var organizes =${flag};
	
	//组织架构初始化
	var organizeSetting = {
		view : {
			dblClickExpand : false
		},
		data : {
			simpleData : {
				enable : true
			}
		},
		callback : {
			beforeClick : beforeClick,
			onClick : organizeOnClick
		}
	};
		//页面加载
	$(function() {
		//设置组织架构弹出框
		$.fn.zTree.init($("#organizesTree"), organizeSetting, organizes);
	});

	//点击事件
	function beforeClick(treeId, treeNode) {
		var check = (treeNode && !treeNode.isParent);
		if (!check)
			alert("请选择下级节点！");
		return check;
	}

	//组织架构点击事件
	function organizeOnClick(e, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("organizesTree"), nodes = zTree.getSelectedNodes(), v = "";
		nodes.sort(function compare(a, b) {
			return a.id - b.id;
		});
		for ( var i = 0, l = nodes.length; i < l; i++) {
			v += nodes[i].name + ",";
		}
		if (v.length > 0)
			v = v.substring(0, v.length - 1);
		var orgNameObj = $("#showOrganize");
		orgNameObj.attr("value", v);
		//设置隐藏域中组织编号  
		$('#orgID').val(treeNode.id);
		hideMenu('organizeContent');
		getContractor(treeNode.id);
	}

	//隐藏组织架构
	function hideMenu(divId) {
		$("#" + divId).fadeOut("fast");
		$("body").unbind("mousedown", {
			tempDiv : divId
		}, onBodyDown);
	}

	//组织架构弹出窗
	function showMenu(objId, divId) {
		var cityObj = $("#" + objId);
		var cityOffset = $("#" + objId).position();
		$("#" + divId).css( {
			left : cityOffset.left + "px",
			top : cityOffset.top + cityObj.outerHeight() + "px"
		}).slideDown("fast");
		$("body").bind("mousedown", {
			tempDiv : divId
		}, onBodyDown);
	}
		//鼠标点击别的地方隐藏弹出属性菜单
	function onBodyDown(event) {
		var divId = event.data.tempDiv;
		if (!(event.target.id == "showOrganize" || $(event.target).parents(
				"#" + divId).length > 0)) {
			hideMenu(divId);
		}
	}
		//参数非空验证
	function paramIsNull(paramId){
		var temp = $('#'+paramId).val();
		if(null == temp || temp=='')
		{
			return false;
		}
		else{
			//文本框去左右空格重新赋值
			$('#'+paramId).val($.trim(temp));
			return true;
		}
	} 
	function getContractor(orgID) {
	if (null != orgID && orgID != '') {
		var url = encodeURI(encodeURI('getContractor.action?contract.contractDepartment=' + orgID));
		$.ajax( {
			url : url,
			type : "POST",
			dataType: "json",
			cache : false,
			success : function(message) {
			    var items = eval(message);
			    if(null != items){
			    var length = items[0].dataListUSER.length;
			    $("#contractor").find("option").remove(); 
			    for(var i=0;i<length;i++)
				    {
				      var name = items[0].dataListUSER[i].userName;
				      var id = items[0].dataListUSER[i].id;
				      jQuery("#contractor").append("<option value="+id+">"+name+"</option>");
				    }
			    }
			}
		});
	}
}
	
	</script>
	
	
	
	</body>
</html>
